package com.wiz.web.controllor;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.wiz.service.AddressService;
import com.wiz.to.AreasTO;
import com.wiz.to.CitiesTO;
import com.wiz.to.ProvincesTO;
import com.wiz.vo.ResponResultVO;
@Controller
@RequestMapping("/address")
public class AddressControllor {
	private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
	@Resource
	private AddressService addressService;
	@RequestMapping(value="/listProvinces")
	@ResponseBody
	public String listProvinces(HttpServletRequest request,HttpServletResponse response,
			HttpSession session, Model model){
		
		List<ProvincesTO> list = addressService.listProvinces();
		ResponResultVO responResultVO = new ResponResultVO(200, "", list, 0, 0, 0);
		return gson.toJson(responResultVO);
		
	}
	@RequestMapping(value="/listCity")
	@ResponseBody
	public String listCity(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "provinceId", required = true) String provinceId,
			HttpSession session, Model model){
		
		List<CitiesTO> list = addressService.listCity(provinceId);
		ResponResultVO responResultVO = new ResponResultVO(200, "", list, 0, 0, 0);
		return gson.toJson(responResultVO);
		
	}
	@RequestMapping(value="/listAreas")
	@ResponseBody
	public String listAreas(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "cityId", required = true) String cityId,
			HttpSession session, Model model){
		
		List<AreasTO> list = addressService.listAreas(cityId);
		ResponResultVO responResultVO = new ResponResultVO(200, "", list, 0, 0, 0);
		return gson.toJson(responResultVO);
		
	}
	
	
	
}
